package de.marantis.app.wow.gfi.gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListModel;
import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

import de.marantis.app.wow.gfi.control.GuiControl;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class UpdateFrame extends javax.swing.JFrame {

	{
		// Set Look & Feel
		try {
			javax.swing.UIManager
					.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public JButton jButton1;
	private JButton jButton4;
	public JLabel jLabel_ausgabe;
	public JTable jTable1;
	public JScrollPane jScrollPane1;
	public JButton jButton3;
	public JLabel jLabel1;
	public JRadioButton jRadioButton3;
	public JRadioButton jRadioButton2;
	public ButtonGroup buttonGroup4;
	public static GuiControl control;
	private JButton jButton5;

	public JRadioButton jRadioButton1;
	public JButton jButton2;

	public UpdateFrame() {
		super();
		// this.control=control;
		this.setResizable(false);
		this.setTitle("Daten aktualisieren");
		initGUI();
	}

	public static GuiControl getControl() {
		return control;
	}

	public static void setControl(GuiControl control) {
		UpdateFrame.control = control;
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
			getContentPane().setLayout(null);
			getContentPane().add(getJScrollPane1());
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Daten aus der Armory ziehen");
				jButton1.addActionListener(new UpdateListener());
				jButton1.setBounds(15, 13, 203, 32);
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("Schliessen");
				jButton2.addActionListener(new CloseListener());
				jButton2.setBounds(580, 424, 146, 38);
			}
			{
				buttonGroup4 = new ButtonGroup();
				jRadioButton1 = new JRadioButton();
				getContentPane().add(jRadioButton1);
				getContentPane().add(getJRadioButton2());
				getContentPane().add(getJRadioButton3());
				getContentPane().add(getJLabel2());
				getContentPane().add(getJButton4());
				getContentPane().add(getJButton5());
				jRadioButton1.setText("Tank");
				buttonGroup4.add(jRadioButton1);
				buttonGroup4.add(jRadioButton2);
				buttonGroup4.add(jRadioButton3);
				jRadioButton1.setBounds(608, 139, 114, 25);
			}
			{

			}
			pack();
			this.setSize(759, 503);
		} catch (Exception e) {
			// add your error handling code here
			e.printStackTrace();
		}
	}

	private ButtonGroup getButtonGroup4() {
		if (buttonGroup4 == null) {
			buttonGroup4 = new ButtonGroup();

		}
		return buttonGroup4;
	}

	private JRadioButton getJRadioButton2() {
		if (jRadioButton2 == null) {
			jRadioButton2 = new JRadioButton();
			jRadioButton2.setText("DD");
			jRadioButton2.setBounds(608, 179, 114, 20);

		}
		return jRadioButton2;
	}

	private JRadioButton getJRadioButton3() {
		if (jRadioButton3 == null) {
			jRadioButton3 = new JRadioButton();
			jRadioButton3.setText("Heiler");
			jRadioButton3.setBounds(608, 216, 114, 20);

		}
		return jRadioButton3;
	}

	private JLabel getJLabel1() {
		if (jLabel1 == null) {
			jLabel1 = new JLabel();
			jLabel1.setText("Update starten");
			jLabel1.setBounds(215, 76, 346, 24);
			jLabel1.setFont(new java.awt.Font("Segoe UI", 0, 14));
		}
		return jLabel1;
	}

	private JButton getJButton3() {
		if (jButton3 == null) {
			jButton3 = new JButton();
			jButton3.setText("Spieler zuordnen");
			jButton3.setBounds(580, 257, 142, 52);
		}
		return jButton3;
	}

	private JScrollPane getJScrollPane1() {
		if (jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setBounds(0, 124, 568, 351);
			jScrollPane1.setViewportView(getJTable1());
		}
		return jScrollPane1;
	}

	private JTable getJTable1() {
		if (jTable1 == null) {
			TableModel jTable1Model = new DefaultTableModel(new String[][] {
					{ "", "" }, { "", "" } }, new String[] { "Name", "Rang",
					"Itemlevel" });
			jTable1 = new JTable() {
				public boolean isCellEditable(int row, int column) { // Editierbarkeit
					return false; // Keine Zelle editierbar
				}
			};
			jTable1.setModel(jTable1Model);
			jTable1.getTableHeader().addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent mouseEvent) {
					int index = jTable1.columnAtPoint(mouseEvent.getPoint());
					// System.out.println(index);
					control.sortierennachSpalteupdate(index);
					
					
				};
			});

			jTable1.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent mouseEvent) {
					
					if (mouseEvent.getClickCount() == 2) {
						control.openDetailFrame(control, 1);
					}
				};
			});
			jTable1.setMaximumSize(new java.awt.Dimension(0, 0));
			jTable1.setMinimumSize(new java.awt.Dimension(0, 0));

		}
		return jTable1;
	}

	private JLabel getJLabel2() {
		if (jLabel_ausgabe == null) {
			jLabel_ausgabe = new JLabel();
			jLabel_ausgabe.setText("Scan bitte starten");
			jLabel_ausgabe.setBounds(244, 12, 281, 32);
			jLabel_ausgabe.setFont(new java.awt.Font("Segoe UI", 0, 14));
		}
		return jLabel_ausgabe;
	}

	private JButton getJButton4() {
		if (jButton4 == null) {
			jButton4 = new JButton();
			jButton4.setText("Zuordnen");
			jButton4.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					// System.out.println(jTable1.getSelectedRow());
					control.zuweisenspieler(jTable1.getSelectedRows());
					// System.out.println(jTable1.getValueAt(jTable1.getSelectedRow(),
					// 0));
				}
			});

			jButton4.setBounds(580, 275, 146, 36);
		}
		return jButton4;
	}

	private JButton getJButton5() {
		if (jButton5 == null) {
			jButton5 = new JButton();
			jButton5.setText("Gildeneinstellungen");
			jButton5.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					// System.out.println(jTable1.getSelectedRow());
					control.gildeneinstellungen(control);
					// System.out.println(jTable1.getValueAt(jTable1.getSelectedRow(),
					// 0));
				}
			});
			jButton5.setBounds(587, 15, 139, 28);
		}
		return jButton5;
	}

	public class UpdateListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			control.datenarmory();
		}

	}

	public class CloseListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			control.updateschliessen();
		}

	}
}
